package com.zh.view.pane

import androidx.compose.foundation.layout.*
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.zh.filetransport.contrl.CommandOpen
import com.zh.view.data.AppStore
import com.zh.view.data.ElMessage

/**
 *
 * @author Zhou
 * @date 20:46 2025/5/30
 */

@Composable
fun SettingsScreen(close: () -> Unit) {
    var remoteIp by remember { mutableStateOf(AppStore.peerIp.value) }

    Column(
        modifier = Modifier.fillMaxSize().padding(16.dp),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {
        Text("本机IP")
        Spacer(modifier = Modifier.height(16.dp))
        TextField(
            value = AppStore.localIp.value,
            onValueChange = {},
            readOnly = true,
            label = { Text("本机IP") }
        )
        Spacer(modifier = Modifier.height(16.dp))
        TextField(
            value = remoteIp,
            onValueChange = { remoteIp = it },
            label = { Text("remote IP") }
        )

        Spacer(modifier = Modifier.height(16.dp))
        Button(onClick = {
//            println("remoteIP = " + remoteIp)
            if (CommandOpen(remoteIp)) {
                AppStore.peerIp.value = remoteIp
                close()
            } else {
                ElMessage.warn("RemoteIP 不可达")
            }
        }) {
            Text("连接")
        }
    }
}
